import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
from joblib import load

class NN(object):
    def __init__(self):
        self.df = pd.read_csv('.data-analysis-1/20250604/scenic_data.csv') 
        self.loaded_model = tf.keras.models.load_model('data-analysis-1/20250604/my_model.keras')  
        self.scaler = load('data-analysis-1/20250604/scaler.joblib')  

    def get_hourly_trend(self):
        """获取预测结果"""
        n_steps = 7

        # 获取最后七天数据
        x_lasters = self.df.iloc[-n_steps:].values  
        x_values = self.df.iloc[-n_steps:]
        x_values.iloc[:, x_values.columns.get_loc('count')] = 0
        x_lasters = x_values.values
        latest_data = x_lasters.reshape(1, n_steps, x_lasters.shape[1])

        # 预测后反归一化
        predicted = self.loaded_model.predict(latest_data)
        predicted_count = self.scaler.inverse_transform(predicted)  # 反归一化
        predicted_count[predicted_count < 0] = 0  # 修正负数

        hourly_trend = predicted_count[0].astype(int).tolist()
        print(hourly_trend)

if __name__ == '__main__':
    nn = NN()
    nn.get_hourly_trend()